package wsz.sharding.algorithm;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * TODO：按照年分片
 * @author wsz
 * @desc：
 * @date 2022/6/7
 */
@Slf4j
public class YearPreciseAlgorithm implements PreciseShardingAlgorithm<Integer> {

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
        String logicTableName = preciseShardingValue.getLogicTableName();
        log.info("tableName={}", logicTableName);
        Integer realTableSuffix = preciseShardingValue.getValue();
        log.info("realTableSuffix={}", realTableSuffix);
        String realTableName = logicTableName.concat("_").concat(String.valueOf(realTableSuffix));
        log.info("realTableName={}", realTableName);
        return realTableName;
    }
}
